package httphandler

import (
	"fmt"
	"net/http"
	"strconv"

	"chat.com/library"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
)

// 聊天页面
func Index(c *gin.Context) {

	appIdStr := c.Query("appId")
	appId, _ := strconv.ParseInt(appIdStr, 10, 64)

	if !library.InAppIds(appId) {
		appId = library.GetDefaultAppId()
	}

	fmt.Println("http_request 聊天首页", appId)

	data := gin.H{
		"title":        "聊天首页",
		"appId":        appId,
		"httpUrl":      viper.GetString("app.httpUrl"),
		"webSocketUrl": viper.GetString("app.webSocketUrl"),
	}

	c.HTML(http.StatusOK, "index.tpl", data)
}
